apply() verses button()

(FYI - this is a newbie question I am sure; I've done only a little DXL coding involving DBs & DBEs)

I thought I could add buttons to a dialog by replacing my apply() calls to button() calls
(I want to do this to be able control the button position).

In my existing, working script, when I do this I get a DXL syntax error:
-E- DXL: <Line:300> incorrect arguments for function (button)

Here is a snippet of the original working code (I have several lines like this):
if (i==8) { apply(dbDoIt,chosenAttrEnumValuesi-1,doSetStatement_Val8) }
New code snippet:
if (i==8) { button(dbDoIt,chosenAttrEnumValuesi-1,doSetStatement_Val8) }

Any ideas what the issue could be?

I now I can do a very simple script and change apply() to button() and it works, hence my confusion!

Thanks,
Strathglass
strathglass - Thu Feb 26 17:18:35 EST 2009

Re: apply() verses button()
Tony_Goodman - Fri Feb 27 04:31:07 EST 2009

Try this:
DB db = null

void doClose(DB db)
{
hide(db)
destroy(db)
db = null
}

void doHelp(DB db)
{
infoBox("Help!")
}

db = create("test")

// hide the default close button which always appears on the far right
// note that the callback is necessary for the X icon to work
close(db, false, doClose)

// create your own buttons - these appear left to right as created
apply(db, "my close", doClose)
apply(db, "my help", doHelp)

realize db

show db

Re: apply() verses button()
Tony_Goodman - Fri Feb 27 04:36:39 EST 2009

Tony_Goodman - Fri Feb 27 04:31:07 EST 2009
Try this:
DB db = null

void doClose(DB db)
{
hide(db)
destroy(db)
db = null
}

void doHelp(DB db)
{
infoBox("Help!")
}

db = create("test")

// hide the default close button which always appears on the far right
// note that the callback is necessary for the X icon to work
close(db, false, doClose)

// create your own buttons - these appear left to right as created
apply(db, "my close", doClose)
apply(db, "my help", doHelp)

realize db

show db

Forgot to say that apply() and ok() create dialog-level buttons. These appear along the bottom of the dialog. Callback takes a DB parameter.

button() creates a dialog box element that happens to be a button. Callback to this takes a DBE parameter.

Re: apply() verses button()
SystemAdmin - Fri Feb 27 04:37:50 EST 2009

The callback function for apply has to have parameter of type DB, for button the parameter has to be of type DBE.

Re: apply() verses button()
strathglass - Fri Feb 27 07:48:04 EST 2009

SystemAdmin - Fri Feb 27 04:37:50 EST 2009
The callback function for apply has to have parameter of type DB, for button the parameter has to be of type DBE.

Thanks Tony & Pekka - I knew it would be something simple & subtle like that! Should have noticed that difference.

Regards,
Strathglass.

Re: apply() verses button()
llandale - Sun Mar 01 15:33:17 EST 2009

strathglass - Fri Feb 27 07:48:04 EST 2009
Thanks Tony & Pekka - I knew it would be something simple & subtle like that! Should have noticed that difference.

Regards,
Strathglass.

Yup, DB or DBE parameters.

Lets take a close peak at the DXL manual for these commands:

1) DBE apply(DB box, string label, void callback(DB))
2) DBE button(DB box, string label, void callback(DBE)) )
3) DBE button(DB box, string label, void callback [, bool variableSize | int style , int width] )

First off; golly I didn't know apply returned a DBE. Wonder what you could do with that. Tried moving it left but it didn't work.

In 1), the label is optional but the button is far too small without a label to be practical. The 3rd paramater says it must be a function with a no return value (void), and that function must have a parameter of type DB. Not sure what you can do with that input DB parameter, unless your script has multiple boxes and you code a single callback for the boxes, and you need to figure out which one was pushed.

In 2) the 3rd parameter callback function must be void and have parameter DBE; and you can have some additional sizing parameters. The input DBE is the handle of the button when its pushed, which you can use to have a single callback distinquish which button was pushed (however, routinely the callback is written for a particular button and therefore 'knows' which button it is, and ignores the parameter).

In 3) we see that 'button' can have another 'width' parameter, and that it doesn't really need the DBE parameter. Turns out that's a misprint, the callback must have a DBE parameter.

2) and 3) also have a misprint, the label is also optional like in 1).

So, your first adventure into reading the manual reveals lots of typos, but there you go.

>Louie